package com.ecosoft.config.spi.property;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ecosoft.config.ConfigContainer;
import com.ecosoft.config.Constants;
import com.ecosoft.config.spi.IConfigContext;
import com.ecosoft.config.spi.IConfigProvider;

public class DefaultPropertyProvider implements IConfigProvider{
	private static final Logger LOG = LoggerFactory.getLogger(DefaultPropertyProvider.class);
	private static String filePattern = "eco-.*\\.properties";
	public void notify(IConfigContext context) {
		LOG.info("DefaultPropertyProvider is being notified to register IConfig to ConfigContainer.register()");
		String rfilePattern = context.getContextAttribute(Constants.DEFAULT_PROPERTIES_ICONFIG_FILE_KEY);
		if(rfilePattern!=null)
		{
			filePattern = rfilePattern;
		}
		File[] files = context.getFileInCommonDirByRegex(filePattern);
		if(files!=null)
		{
			for(File file:files)
			{
				PropertyConfig config = new PropertyConfig(file.getAbsolutePath());
				ConfigContainer.register(config);
			}
		}
	}
 
}
